package com.gpframework.module.controller.process;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.process.domain.GpProcessIncomingInspectWidth;
import com.gpframework.module.process.domain.vo.GpProcessIncomingInspectWidthVo;
import com.gpframework.module.process.domain.req.GpProcessIncomingInspectWidthReq;
import com.gpframework.module.process.domain.req.GpProcessIncomingInspectWidthAdd;
import com.gpframework.module.process.domain.req.GpProcessIncomingInspectWidthUpdate;
import com.gpframework.module.process.service.IGpProcessIncomingInspectWidthService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpProcessIncomingInspectWidthController
 * @Author gpframework
 * @Date 2023-12-20
 * @Version 1.0.0
 * @Description 加工来料检验单幅宽Controller
 */
@Validated
@Api(tags = "加工来料检验单幅宽")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/process/width" )
public class GpProcessIncomingInspectWidthController extends BaseController {

    private final IGpProcessIncomingInspectWidthService iGpProcessIncomingInspectWidthService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-12-20
  * @Param gpProcessIncomingInspectWidth
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('process:width:list')")
    @GetMapping("/list")
    public TableDataInfo<GpProcessIncomingInspectWidthVo> list(GpProcessIncomingInspectWidthReq gpProcessIncomingInspectWidthReq)
    {
        startPage();
        QueryWrapper<GpProcessIncomingInspectWidth> lqw = new QueryWrapper<GpProcessIncomingInspectWidth>();
        gpProcessIncomingInspectWidthReq.generatorQuery(lqw,true);
        List<GpProcessIncomingInspectWidthVo> list = iGpProcessIncomingInspectWidthService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2023-12-20
     * @Param gpProcessIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('process:width:add')" )
    @Log(title = "添加加工来料检验单幅宽" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpProcessIncomingInspectWidthAdd gpProcessIncomingInspectWidthAdd) {
        GpProcessIncomingInspectWidth gpProcessIncomingInspectWidth = Convert.convert(new TypeReference<GpProcessIncomingInspectWidth>() {}, gpProcessIncomingInspectWidthAdd);
        return toAjax(iGpProcessIncomingInspectWidthService.save(gpProcessIncomingInspectWidth) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-12-20
     * @Param gpProcessIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('process:width:edit')" )
    @Log(title = "修改加工来料检验单幅宽" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpProcessIncomingInspectWidthUpdate gpProcessIncomingInspectWidthUpdate) {
        GpProcessIncomingInspectWidth gpProcessIncomingInspectWidth = Convert.convert(new TypeReference<GpProcessIncomingInspectWidth>() {}, gpProcessIncomingInspectWidthUpdate);
        return toAjax(iGpProcessIncomingInspectWidthService.updateById(gpProcessIncomingInspectWidth) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2023-12-20
     * @Param gpProcessIncomingInspectWidth
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('process:width:export')" )
    @Log(title = "导出加工来料检验单幅宽" , businessType = BusinessType.EXPORT)
    @ApiOperation("导出加工来料检验单幅宽")
    @GetMapping("/export" )
    public AjaxResult export(GpProcessIncomingInspectWidthReq gpProcessIncomingInspectWidthReq) {
        QueryWrapper<GpProcessIncomingInspectWidth> lqw = new QueryWrapper<GpProcessIncomingInspectWidth>();
        gpProcessIncomingInspectWidthReq.generatorQuery(lqw,true);
        List<GpProcessIncomingInspectWidthVo> list = iGpProcessIncomingInspectWidthService.listVo(lqw);
        ExcelUtil<GpProcessIncomingInspectWidthVo> util = new ExcelUtil<GpProcessIncomingInspectWidthVo>(GpProcessIncomingInspectWidthVo. class);
        return util.exportExcel(list, "width" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-12-20
     * @Param gpProcessIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('process:width:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpProcessIncomingInspectWidthVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpProcessIncomingInspectWidthService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-12-20
     * @Param gpProcessIncomingInspectWidth
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('process:width:remove')" )
    @Log(title = "删除加工来料检验单幅宽" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpProcessIncomingInspectWidthService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
